package com.xafc.demo.framework.utils;

import cn.hutool.core.util.StrUtil;
import com.xafc.demo.security.utils.CurrentUser;
import com.xafc.demo.security.utils.UserHolderUtils;


/**
 * Freemarker模板文件工具类
 */
public class FreemarkerFunUtil {


    /**
     * 判断用户是否登录
     */
    public boolean isLogin() {
        return null != this.getUser();
    }

    /**
     * 获取当前登录用户信息
     */
    public CurrentUser getUser() {
        CurrentUser currentUser = UserHolderUtils.getUser();
        if (currentUser != null){
            return currentUser;
        }

        return null;
    }

    /**
     * 获取当前登录用户用户名
     */
    public String getUserName() {
        final CurrentUser user = this.getUser();
        if(null == user){
            return StrUtil.EMPTY;
        }
        return user.getUsername();
    }

}
